﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Windows.Forms.DataVisualization.Charting;

namespace FrmHotel
{
    public partial class FrmTongJi : Form
    {
        public FrmTongJi()
        {
            InitializeComponent();
        }

       

        private void button3_Click(object sender, EventArgs e)
        {

            
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
        }

        private void FrmTongJi_Load(object sender, EventArgs e)
        {
            sata();
        }

        public void sata()
        {
            this.dataGridView1.AutoGenerateColumns = false;
            string sql = "select t.*,r.RmId,c.CeName,o.CyName from TongJioo t,RoomInfo r,CetaeInfo c ,Commodity o where t.CsoRoom=r.RmId and t.CsoName=c.CeId and t.SsoName=o.CyId and 1=1";
            string id = this.textBox1.Text;
            if (!string.IsNullOrEmpty(id))
            {
                sql += string.Format(" and CsoRoom like '%{0}%'", id);
            }
            string name = this.textBox2.Text;
            if (!string.IsNullOrEmpty(name))
            {
                sql += string.Format(" and SsoName  like '%{0}%'", name);
            }
            this.dataGridView1.DataSource = FrmHotel.DBHelper.SelectForTable(sql);
        }
        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void tabPage2_Click(object sender, EventArgs e)
        {

        }

        private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
        {

        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void chart1_Click(object sender, EventArgs e)
        {

        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void chart2_Click(object sender, EventArgs e)
        {

        }

        private void dateTimePicker3_ValueChanged(object sender, EventArgs e)
        {

        }

        private void dateTimePicker4_ValueChanged(object sender, EventArgs e)
        {

        }

        private void tabPage3_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
          
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            string sql = string.Format(@"select sum(chhmoney) as x,DATEPART(yyyy, Tjdate) as j from Tongji 
            where Tjdate between '{0}' and '{1}' group by DATEPART(yyyy, Tjdate)", dateTimePicker6.Text, dateTimePicker5.Text);
            DataTable dt = DBHelper.SelectForTable(sql);
            chart3.Series.Clear();
            Series cs = new Series();
            cs.ChartType = SeriesChartType.Column;
            chart3.ChartAreas[0].Area3DStyle.Enable3D = false;
            chart3.Series.Add(cs);
            chart3.Series[0].YValueMembers = "x";
            chart3.Series[0].XValueMember = "j";
            chart3.Series[0].Label = "#VAL";
            //chart1.Series[0].ToolTip = "XXXXX:#VAL";
            chart3.Series[0].LegendText = "每年的消费统计";
            chart3.DataSource = dt;
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            string sql = string.Format(@"select sum(chhmoney) as x,DATEPART(MM, Tjdate) as j from Tongji 
            where Tjdate between '{0}' and '{1}' group by DATEPART(MM, Tjdate)", dateTimePicker4.Text, dateTimePicker3.Text);
            DataTable dt = DBHelper.SelectForTable(sql);
            chart2.Series.Clear();
            Series cs = new Series();
            cs.ChartType = SeriesChartType.Column;
            chart2.ChartAreas[0].Area3DStyle.Enable3D = false;
            chart2.Series.Add(cs);
            chart2.Series[0].YValueMembers = "x";
            chart2.Series[0].XValueMember = "j";
            chart2.Series[0].Label = "#VAL";
            //chart1.Series[0].ToolTip = "XXXXX:#VAL";
            chart2.Series[0].LegendText = "每月的消费统计";
            chart2.DataSource = dt;
        }

        private void button3_Click_2(object sender, EventArgs e)
        {
            string sql = string.Format(@"select sum(chhmoney) as x,DATEPART(dd, Tjdate) as j from Tongji 
            where Tjdate between '{0}' and '{1}' group by DATEPART(dd, Tjdate)", dateTimePicker1.Text, dateTimePicker2.Text);
            DataTable dt = DBHelper.SelectForTable(sql);
            chart1.Series.Clear();
            Series cs = new Series();
            cs.ChartType = SeriesChartType.Column;
            chart1.ChartAreas[0].Area3DStyle.Enable3D = false;
            chart1.Series.Add(cs);
            chart1.Series[0].YValueMembers = "x";
            chart1.Series[0].XValueMember = "j";
            chart1.Series[0].Label = "#VAL";
            //chart1.Series[0].ToolTip = "XXXXX:#VAL";
            chart1.Series[0].LegendText = "每日的消费统计";
            chart1.DataSource = dt;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            sata();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            sata();
        }
    }
}
